﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manage_Questions : ManagePageBase {

    protected List<Exam.Core.Model.Course> list = new List<Exam.Core.Model.Course>();

    protected void Page_Load(object sender, EventArgs e) {
        if(!IsPostBack){
            getCourse();
        }
    }

    private void getCourse() {

        list = new Exam.Core.DAL.Course().getCoursesListByMasterId(isTheMe.MasterID);//培训师管理的课程

            int know = 0;
            int qnumber = 0;
            foreach (Exam.Core.Model.Course obj in list)
            {
                know = know + int.Parse(obj.KnowCount);
                qnumber = qnumber + int.Parse(obj.QuestionCount);
            }
            string tmp = Resources.labels.have_course_know_question;
            tmp = string.Format(tmp, list.Count, know, qnumber);
            Labtj.Text = tmp;//"您共有 " + list.Count + "门课程 " + know + "个知识点，" + qnumber + "道试题";

            list.Sort();

            int total = list.Count; //总记录数
            AspNetPager1.RecordCount = total;
            int pagesize = 5;//每页显示数目
            int count = Math.Min(pagesize, total);
            int page = GetPageIndex();
            int index = page * count;
            int stop = count;
            if (index + count > total)
                stop = total - index;

            if (stop < 0 || stop + index > total)
            {
                AspNetPager1.Visible = false;
            }
            list = list.GetRange(index, stop);

    }

    private int GetPageIndex() {
        int index = 0;
        if (int.TryParse(Request.QueryString["page"], out index))
            index--;
        return index;
    }

}
